package leetcode.hash;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @author mazouri
 * @create 2021-09-25 23:36
 */
public class _1394_findLucky {
    public int findLucky(int[] arr) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int res = -1;
        for (int i : arr) {
            map.put(i,map.getOrDefault(i,0)+1);
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (entry.getKey().equals(entry.getValue())){
                res = Math.max(res,entry.getValue());
            }
        }

        return res;
    }
}
